package io.esirong.widget;

import android.view.animation.AccelerateInterpolator;

import java.lang.reflect.Field;

import androidx.viewpager.widget.ViewPager;

/**
 * @ClassName: FixedScrollerSpeed
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author: huangrongcai
 * @date: 2024/4/21
 * @Copyright: 黄嵘才（HuangRc)
 */
class FixedScrollerSpeed {

    /**
     * 设置Viewpager的滚动速度
     * @param mViewPager ViewPager
     */
    public void setViewPager(ViewPager mViewPager) {
        try {
            Field field = ViewPager.class.getDeclaredField("mScroller");
            field.setAccessible(true);
            FixedSpeedScroller scroller = new FixedSpeedScroller(mViewPager.getContext(), new AccelerateInterpolator());
            field.set(mViewPager, scroller);
            scroller.setDuration(300);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
